import Flutter
import AVFoundation

public class IosCameraPermissionPlugin: NSObject, FlutterPlugin {
    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "ios_camera_permission", binaryMessenger: registrar.messenger())
        let instance = IosCameraPermissionPlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
    }
    
    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        switch call.method {
        case "getCameraPermission":
            result(AVCaptureDevice.authorizationStatus(for: .video).rawValue)
        case "requestCameraPermission":
            AVCaptureDevice.requestAccess(for: .video) { (granted) in
                result(granted)
            }
        default:
            result(FlutterMethodNotImplemented)
        }
    }
}
